
from flask_pagedown.fields import PageDownField
from wtforms import StringField,PasswordField,SubmitField,SelectField,TextAreaField
from wtforms.validators import DataRequired,EqualTo,Email,Length,URL
from flask_wtf import FlaskForm
from flask_wtf.file import FileField,FileAllowed,FileRequired
from models import Groupq,Forumq


class Signupmd(FlaskForm):
    username=StringField(label="用户名",validators=[DataRequired('用户名不能为空'),Length(max=20,message="用户名最长20")])
    mail=StringField(label="邮箱",validators=[DataRequired('邮箱不能为空'),Email("邮箱格式错误！"),Length(max=64,message="你的邮箱名为啥这么长？")])
    password=PasswordField(label="密码",validators=[DataRequired('密码不能为空'),Length(max=128,message="你的密码都超过128了")])
    password2=PasswordField(label="再次输入密码",validators=[DataRequired("密码不能为空"),EqualTo('password',message="密码不能不同")])
    ques1=StringField(label="验证问题",validators=[DataRequired("请回答问题")])
    submit=SubmitField(label="注册")    

class Logininmd(FlaskForm):
    username=StringField(label="用户名",validators=[DataRequired('请输入用户名'),Length(max=20,message="用户名最长20，你是怎么注册的？")])
    password=PasswordField(label="密码",validators=[DataRequired('请输入密码')])
    submit=SubmitField(label="登录")

class Uploadmd(FlaskForm):
    ftmp=FileField(label="上传压缩包",validators=[FileRequired('文件未上传'),FileAllowed(["tar.xz","tar","tar.gz","7z","zip","rar"],"文件必须为压缩包")])
   
    submit=SubmitField(label="提交")

class PostArticle(FlaskForm):
    #forums=Forumq.query.all()
    #choices=[(forum.fo_id,forum.fo_name) for forum in forums]
    title=StringField(label="标题",validators=[DataRequired('记得标题'),Length(max=128,message="不是都说了标题最长128么")])
    #coverimg=StringField(label="插图",validators=[Length(max=255),URL("好歹是url啊")])
    #foid=SelectField(label="论坛",validators=[DataRequired('请选择论坛')],render_kw={'class': 'form-control'},choices=choices,default = 1,coerce=int)
    context=PageDownField(label="正文",validators=[DataRequired('记得写内容啊'),Length(max=65535,message="不是都说了标题最长65535么")])
    submit=SubmitField(label="提交")


class Comments(FlaskForm):
    context=PageDownField(label="发表评论",validators=[DataRequired("评论内容不能空啊"),Length(max=65535,message="不是都说了评论最长65535么")])
    submit=SubmitField(label="提交")

class Uploadimgmd(FlaskForm):
    ftmp=FileField(label="上传图片",validators=[FileRequired('文件未上传'),FileAllowed(["jpg","gif","png","bmp","jpeg"],"文件必须为图片")])
    submit=SubmitField(label="提交")

class Award(FlaskForm):
    groups=Groupq.query.all()
    choices=[(group.g_id,group.g_name) for group in groups]
    uid_select=StringField(label='用户id',validators=[DataRequired('请输入用户uid')])
    ftm=SelectField(label='用户组',validators=[DataRequired('请选择职位')],render_kw={'class': 'form-control'},choices=choices,default = 3,coerce=int)
    submit=SubmitField(label="提交")


class CreateForum(FlaskForm):
    fo_name=StringField(label="论坛名",validators=[DataRequired('记得写论坛名啊'),Length(max=20,message="不是都说了论坛名最长20个字符么")])
    #fo_parent=IntegerField(label="父论坛id（可选）")
    fo_descr=TextAreaField(label="论坛介绍（可选）")
    submit=SubmitField(label="创建")